{% load humanize %}
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>MalSpider - Security Alerts</title>

    <!-- Bootstrap Core CSS -->
    <link href="{% static "bower_components/bootstrap/dist/css/bootstrap.min.css" %}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="{% static "bower_components/metisMenu/dist/metisMenu.min.css" %}" rel="stylesheet">
    
    <!-- Custom CSS -->
    <link href="{% static "dist/css/sb-admin-2.css" %}" rel="stylesheet">

   <link href="{% static "bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" %}" rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="{% static "bower_components/datatables-responsive/css/responsive.dataTables.css" %}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="{% static "bower_components/font-awesome/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- jQuery -->
    <script src="{% static "bower_components/jquery/dist/jquery.min.js" %}"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });

    });
    </script>
    <!-- Bootstrap Core JavaScript -->
    <script src="{% static "bower_components/bootstrap/dist/js/bootstrap.min.js" %}"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="{% static "bower_components/metisMenu/dist/metisMenu.min.js" %}"></script>

    <!-- DataTables JavaScript -->
    <script src="{% static "bower_components/datatables/media/js/jquery.dataTables.min.js" %}"></script>
    <script src="{% static "bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js" %}"></script>

    <!-- Custom Theme JavaScript -->
    <script src="{% static "dist/js/sb-admin-2.js" %}"></script>

<script>
$(document).ready(function() {
	$("button").click(function() {
   		button_id = String(this.id);
   		if (button_id && button_id.startsWith("fpSubmit_")) {
			btn_split = button_id.split("_");
			if (btn_split.length == 2) {
				frm_id = "#fpForm_" + btn_split[1];
				frm_modal_id = "#fpModal_" + btn_split[1];
				frm_data = $(frm_id).serialize();
				$(frm_modal_id).find('.modal-body').html("<b>Processing! Please wait!</b><br/>This may take up to 1 minute on large datasets. This page will reload when finished.");
				$(frm_modal_id).find('.modal-footer').html("");
				$.ajax({
					type: 'POST',
					url: '/fp',
					data: frm_data
				})
				.done(function(data) {
					$(frm_modal_id).modal('toggle');
					location.reload();
				})
				.fail(function() {
					$(frm_modal_id).find('.modal-body').html("Error Processing Request!");
				});

			}
		}

	});
});
</script>

</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
	<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">MalSpider</a>
            </div>
            <!-- /.navbar-header -->

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        <li>
                            <a href="/"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
                        </li>
			<li>
                            <a href="/admin"><i class="fa fa-wrench fa-fw"></i>Admin Panel</a>
                        </li>
                        <li>
                            <a href="/daemon"><i class="fa fa-gears fa-fw"></i>Spider Daemon</a>
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-bell fa-fw"></i>View Alerts<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="/alerts/last_24_hours/">Last 24 Hours</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_3_days/">Last 3 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_7_days/">Last 7 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_30_days/">Last 30 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/last_90_days/"> Last 90 Days</a>
                                </li>
                                <li>
                                    <a href="/alerts/all_time/">All Time</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>

        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Security Alerts</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <div class="row">
		<div class="col-lg-12">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>Security Alert</th>
                                            <th>Found on Page</th>
                                            <th>Requested Resource</th>
					    <th>Raw HTML</th>
                                        </tr>
                                    </thead>
                                    <tbody>
				{% if alerts %}
		    		{% for alert in alerts %}
					<tr><td class="text-danger">{{alert.reason}}</td><td>{{alert.page|truncatechars:75}}</td><td>{{alert.uris|linebreaksbr}}</td><td><button class="btn btn-warning" data-toggle="modal" data-target="#myModal_{{alert.id}}">Raw Code</button><button class="btn btn-success" data-toggle="modal" data-target="#fpModal_{{alert.id}}">False Positive</button></td></tr>
				<div class="modal fade" id="myModal_{{alert.id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModalLabel">Raw HTML</h4>
                                        </div>
                                        <div class="modal-body">
                                            <code>{{alert.raws|linebreaksbr}}</code>
                                       </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        </div>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
				</div>
                                <!-- /.modal-dialog -->
				<div class="modal fade" id="fpModal_{{alert.id}}" tabindex="-1" role="dialog" aria-labelledby="myModal2" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModal2">Is this a false positive?</h4>
                                        </div>
                                        <div class="modal-body" id="fpModalBody">
					    <div class="container-fluid">

						<form id="fpForm_{{alert.id}}" method="post">
						<input type="hidden" name="alert_ids" id="alert_ids" value="{{alert.alert_ids}}">
						<div class="row">
							<div class="col-md-12"><b>Page:</b>  {{alert.page}}</div>
						</div>
						<div class="row" style="margin-bottom: 25px;"></div>
						<div class="row">
                                            		<div class="col-md-12"><code>{{alert.uris|linebreaksbr}}</code></div>
						</div>
						<div class="row" style="margin-bottom: 25px;"></div>
						<div class="row">
							<div class="col-md-12 form-group">
            							<label for="whitelist_pattern" class="form-control-label">Whitelist Pattern (Optional)</label>
								<p><b>Examples:</b> google.com, google, query_parameter</p> 
            							<input type="text" class="form-control" id="whitelist_pattern" name="whitelist_pattern">
          						</div>
						</div>
						<div class="row">
							<div class="col-md-12 form-group">
							<input type="radio" name="remove" value="remove_all" checked="checked" /> Remove all instances of this false positve and don't show again<br>
							<input type="radio" name="remove" value="remove_once" /> Remove this instance only<br>
							</div>
						</div>
					        </form>
					   </div>
					</div>
					<div class="modal-footer">		
					   <div class="container-fluid">
						<div class="row">
                                              		<div class="col-md-12">
							<button id="fpSubmit_{{alert.id}}" class="btn btn-success">Submit False Positive</button>
                                              		</div>
                                            	</div>
					    </div>
                                       </div>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
				</div>
                                <!-- /.modal-dialog -->
		    		{% endfor %}
				{% else %}
					<tr><td colspan=4><p class="text-center">No alerts found!</p></td></tr>
				{% endif %}
				    </tbody>
				</table>
                                <div>
                                        <a href="/export/{{time_frame}}" class="btn btn-success" role="button">Export as CSV</a>
                                </div>
			    </div>
			</div>
		    </div>
		</div>
            </div>
            <!-- /.row -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
</body>

</html>
